package com.kurumi.thread;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kurumi.constant.HomepageConstatnt;
import com.kurumi.domain.PractitionerVO;
import com.kurumi.domain.ShandongHomepageExcelDTO;
import com.kurumi.service.MedicalRecordDataManageService;
import com.kurumi.util.DateUtil;
import com.kurumi.util.ObjectUtils;
import com.kurumi.util.ReflectHelper;

/**
 * 首页数据处理多线程
 *
 * @author liyutao
 *
 */
public class HomePageHandleCallable implements Callable<List<ShandongHomepageExcelDTO>> {

	private static final Logger logger = LoggerFactory.getLogger(HomePageHandleCallable.class);

	/**
	 * 分批guid集合
	 */
	private List<String> guidList;

	private MedicalRecordDataManageService medicalRecordDataManageService;

	public HomePageHandleCallable() {

	}

	public HomePageHandleCallable(List<String> guidList,
			MedicalRecordDataManageService medicalRecordDataManageService) {
		this.guidList = guidList;
		this.medicalRecordDataManageService = medicalRecordDataManageService;
	}

	@Override
	public List<ShandongHomepageExcelDTO> call() throws Exception {
		List<ShandongHomepageExcelDTO> homepageHandleDataList = new ArrayList<>();
		ShandongHomepageExcelDTO homepageData = null;
		for (String guid : guidList) {
			// 查询病案json
			Map<String, Object> jsonMap = medicalRecordDataManageService.getMedicalRecordMapByGuid(guid);
			//System.out.println(jsonMap);
			//logger.info("线程：{}，正在处理guid为:{}的数据", Thread.currentThread().getName(), guid);
			homepageData = new ShandongHomepageExcelDTO();
			// 初始化常量信息
			initHomepageData(homepageData);
			// 初始化基本信息
			handleHomepageBaiscData(jsonMap, homepageData);
			// 处理治疗信息
			handleCureInfoData(jsonMap, homepageData);
			// 处理诊断信息
			handleDiagInfo(jsonMap, homepageData);

			// 处理护理记录
			handleNurseInfo(jsonMap, homepageData);

			// 处理手术信息
			hadleOperationInfo(jsonMap, homepageData);

			// 处理费用信息
			hadleCostInfo(jsonMap, homepageData);

			// 处理输血信息
			handleInfusionBloodInfo(jsonMap, homepageData);


			homepageHandleDataList.add(homepageData);
		}
		return homepageHandleDataList;
	}

	/**
	 * 处理输血信息
	 * @param jsonMap
	 * @param homepageData
	 */
	private void handleInfusionBloodInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> infusionBloodInfo = MapUtils.getMap(jsonMap, "infusionBloodInfo");
		if (MapUtils.isEmpty(infusionBloodInfo)) {
			homepageData.setSXFY("0");
			return;
		}

		// 输血反应次数
		// 0	未输
		// 1	有
		// 2	无
		Integer infusionBloodReactTimes = MapUtils.getInteger(infusionBloodInfo, "infusionBloodReactTimes");
		if(infusionBloodReactTimes!=null && infusionBloodReactTimes>0) {
			homepageData.setSXFY("1");
		}else {
			homepageData.setSXFY("2");
		}

		// 输血记录
		List<Map<String,Object>> infusionBloodRecords = (List<Map<String, Object>>) MapUtils.getObject(infusionBloodInfo, "infusionBloodRecords");
		// 红细胞
		double redCellCount = 0;
		// 血小板
		double bloodCellCount = 0;
		// 血浆
		double plasmaCount = 0;
		// 全血
		double wholeBloodCount = 0;
		// 自体血回输
		double selfBloodCount = 0;
		if(CollectionUtils.isNotEmpty(infusionBloodRecords)) {
			for (Map<String, Object> infusionBloodRecord : infusionBloodRecords) {
				List<Map<String,Object>> infusionBloodElements = (List<Map<String, Object>>) MapUtils.getObject(infusionBloodRecord, "infusionBloodElements");
				for (Map<String, Object> infusionBloodElement : infusionBloodElements) {
					String bloodElementCode = MapUtils.getString(infusionBloodElement, "bloodElementCode");
					double bloodElementVolume = MapUtils.getDoubleValue(infusionBloodElement, "bloodElementVolume");
					// 红细胞
					if("B0001".equals(bloodElementCode)) {
						redCellCount += bloodElementVolume;
					// 血小板
					}else if("B0003".equals(bloodElementCode)) {
						bloodCellCount += bloodElementVolume;
					// 血浆
					}else if("B0004".equals(bloodElementCode)) {
						plasmaCount += bloodElementVolume;
					// 全血
					}else if("B0005".equals(bloodElementCode)) {
						wholeBloodCount += bloodElementVolume;
					// 自体血回输
					}else if("B0006".equals(bloodElementCode)) {
						selfBloodCount += bloodElementVolume;
					}
				}

			}
		}
		homepageData.setHXB(Double.toString(redCellCount));
		homepageData.setXXB(Double.toString(bloodCellCount));
		homepageData.setXJ(Double.toString(plasmaCount));
		homepageData.setQX(Double.toString(wholeBloodCount));
		homepageData.setZTXHS(Double.toString(selfBloodCount));



	}

	/**
	 * 处理费用信息
	 *
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleCostInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> costInfoMap = MapUtils.getMap(jsonMap, "costInfo");
		if (MapUtils.isEmpty(costInfoMap)) {
			return;
		}
		// 住院总费用
		String ZFY = ObjectUtils.getStringValue(costInfoMap.get("totalCost"));
		homepageData.setZFY(ZFY);
		// 住院总费用其中自付金额
		String ZFJE = ObjectUtils.getStringValue(costInfoMap.get("selfCost"));
		homepageData.setZFJE(ZFJE);

		List<Map<String, Object>> costRecords = (List<Map<String, Object>>) MapUtils.getObject(costInfoMap,
				"costRecords");
		if (CollectionUtils.isNotEmpty(costRecords)) {
			for (Map<String, Object> costRecord : costRecords) {

				String medicalCostTypeCode = MapUtils.getString(costRecord, "medicalCostTypeCode");
				String money = MapUtils.getString(costRecord, "costMoney");
				// 1.一般医疗服务费
				if ("C01001".equals(medicalCostTypeCode)) {
					homepageData.setYLFUF(money);
				// 2.一般治疗操作费
				}else if("C01002".equals(medicalCostTypeCode)) {
					homepageData.setZLCZF(money);
				// 3.护理费
				}else if("C01003".equals(medicalCostTypeCode)) {
					homepageData.setHLF(money);
				// 4.综合医疗服务类其他费用
				}else if("C01999".equals(medicalCostTypeCode)) {
					homepageData.setQTFY(money);
				// 5.病理诊断费
				}else if("C02001".equals(medicalCostTypeCode)) {
					homepageData.setBLZDF(money);
				// 6.实验室诊断费
				}else if("C02002".equals(medicalCostTypeCode)) {
					homepageData.setSYSZDF(money);
				// 7.影像学诊断费
				}else if("C02003".equals(medicalCostTypeCode)) {
					homepageData.setYXXZDF(money);
				// 8.临床诊断项目费
				}else if("C02004".equals(medicalCostTypeCode)) {
					homepageData.setLCZDXMF(money);
				// 9.非手术治疗项目费
				}else if("C03001".equals(medicalCostTypeCode)) {
					homepageData.setFSSZLXMF(money);
				// 其中：临床物理治疗费
				}else if("C03002".equals(medicalCostTypeCode)) {
					homepageData.setWLZLF(money);
				// 10.手术治疗费
				}else if("C03003".equals(medicalCostTypeCode)) {
					homepageData.setSSZLF(money);
				// 其中：麻醉费
				}else if("C03004".equals(medicalCostTypeCode)) {
					homepageData.setMAF(money);
				// 其中：手术费
				}else if("C03005".equals(medicalCostTypeCode)) {
					homepageData.setSSF(money);
				// 11.康复费	KFF
				}else if("C04001".equals(medicalCostTypeCode)) {
					homepageData.setKFF(money);
				// 12.中医治疗费	ZYZLF
				}else if("C05001".equals(medicalCostTypeCode)) {
					homepageData.setZYZLF(money);
				// 13.西药费	XYF
				}else if("C06001".equals(medicalCostTypeCode)) {
					homepageData.setXYF(money);
				// 其中：抗菌药物费	KJYWF
				}else if("C06002".equals(medicalCostTypeCode)) {
					homepageData.setKJYWF(money);
				// 14.中成药费	ZCYF
				}else if("C07001".equals(medicalCostTypeCode)) {
					homepageData.setZCYF(money);
				// 15.中草药费	ZCYF1
				}else if("C07002".equals(medicalCostTypeCode)) {
					homepageData.setZCYF1(money);
				// 16.血费	XF
				}else if("C08001".equals(medicalCostTypeCode)) {
					homepageData.setXF(money);
				// 17.白蛋白类制品费	BDBLZPF
				}else if("C08002".equals(medicalCostTypeCode)) {
					homepageData.setBDBLZPF(money);
				// 18.球蛋白类制品费	QDBLZPF
				}else if("C08003".equals(medicalCostTypeCode)) {
					homepageData.setQDBLZPF(money);
				// 19.凝血因子类制品费	NXYZLZPF
				}else if("C08004".equals(medicalCostTypeCode)) {
					homepageData.setNXYZLZPF(money);
				// 20.细胞因子类制品费
				}else if("C08005".equals(medicalCostTypeCode)) {
					homepageData.setXBYZLZPF(money);
				// 21.检查用一次性医用材料费	HCYYCLF
				}else if("C09001".equals(medicalCostTypeCode)) {
					homepageData.setHCYYCLF(money);
				// 22.治疗用一次性医用材料费	YYCLF
				}else if("C09002".equals(medicalCostTypeCode)) {
					homepageData.setYYCLF(money);
				// 23.手术用一次性医用材料费	YCXYYCLF
				}else if("C09003".equals(medicalCostTypeCode)) {
					homepageData.setYCXYYCLF(money);
				// 24.其他费：	QTF
				}else if("C99999".equals(medicalCostTypeCode)) {
					homepageData.setQTF(money);
				}
			}
		}

	}

	/**
	 * 处理手术相关数据信息
	 *
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleOperationInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> operationInfoMap = MapUtils.getMap(jsonMap, "hqmsOperateInfo");
		if (MapUtils.isEmpty(operationInfoMap)) {
			return;
		}
		// 获取手术信息集合
		List<Map<String, Object>> operateRecords = (List<Map<String, Object>>) MapUtils.getObject(operationInfoMap,
				"operateRecords");
		if (CollectionUtils.isEmpty(operateRecords)) {
			return;
		}

		int opsIndex = 1;
		for (Map<String, Object> operateRecord : operateRecords) {

			ReflectHelper reflectHelper = new ReflectHelper(homepageData);// 创建工具类对象
			// 手术操作编码
			reflectHelper.setMethodValue("SSJCZBM" + opsIndex, MapUtils.getString(operateRecord, "operateCode"));
			// 手术操作日期
			String operateTimeStr = MapUtils.getString(operateRecord, "operateStartDate");
			reflectHelper.setMethodValue("SSJCZRQ" + opsIndex, operateTimeStr);
			// 手术操作名称
			reflectHelper.setMethodValue("SSJCZMC" + opsIndex, MapUtils.getString(operateRecord, "operateName"));
			// 手术类型
			reflectHelper.setMethodValue("SSLX" + opsIndex, MapUtils.getString(operateRecord, "patientSourceCode"));
			// 手术操作级别
			reflectHelper.setMethodValue("SSJB" + opsIndex, MapUtils.getString(operateRecord, "opsLevelCode"));
			// 切口等级
			String incisionLevelCode = MapUtils.getString(operateRecord, "incisionLevelCode");
			if(StringUtils.isNotEmpty(incisionLevelCode)) {
				reflectHelper.setMethodValue("QKDJ" + opsIndex, convertIncisionType(incisionLevelCode));
			}

			// 手术操作切口愈合类别
			String cicatrizeTypeCode = MapUtils.getString(operateRecord, "cicatrizeTypeCode");
			if(StringUtils.isNotBlank(cicatrizeTypeCode)) {
				if("5".equals(cicatrizeTypeCode)) {
					cicatrizeTypeCode = null;
				}
				reflectHelper.setMethodValue("QKYHLB" + opsIndex,cicatrizeTypeCode);
			}

			// 麻醉方式
			String anaesthesiaTypeCode = MapUtils.getString(operateRecord, "anaesthesiaTypeCode");
			if (StringUtils.isNotBlank(anaesthesiaTypeCode)) {
				// 从转换信息中获取上报麻醉方式code
				reflectHelper.setMethodValue("MZFS" + opsIndex, getAnaesthesiaMap().get(anaesthesiaTypeCode));
			}

			// 麻醉分级
			reflectHelper.setMethodValue("MZFJ" + opsIndex, MapUtils.getString(operateRecord, "anaesthesiaLevelCode"));
			List<Map<String, Object>> operateWorkers = (List<Map<String, Object>>) MapUtils.getObject(operateRecord,
					"operateWorkers");

			// 手术操作持续时间
			String opsStartTimeStr = MapUtils.getString(operateRecord, "operateStartDate");
			String opsEndTimeStr = MapUtils.getString(operateRecord, "operateStartDate");
			if (StringUtils.isNotEmpty(opsStartTimeStr) && StringUtils.isNotEmpty(opsEndTimeStr)) {
				try {
					Date opStartTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", opsStartTimeStr);
					Date opEndTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", opsEndTimeStr);
					long betweenmilliseconds = opEndTime.getTime() - opStartTime.getTime();
					long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
					long nh = 1000 * 60 * 60;// 一小时的毫秒数
					int hour = (int) (betweenmilliseconds % nd / nh);// 计算差多少小时
					reflectHelper.setMethodValue("SSCXSJ" + opsIndex, hour+"");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			// 手术医师
			if (CollectionUtils.isNotEmpty(operateWorkers)) {

				for (Map<String, Object> operateWorker : operateWorkers) {
					String professionTitleCode = MapUtils.getString(operateWorker, "professionTitleCode");
					String medicalWorkerName = MapUtils.getString(operateWorker, "medicalWorkerName");
					String medicalWorkerCode = MapUtils.getString(operateWorker, "medicalWorkerCode");
					PractitionerVO practitionerVO = null;
					// 执业人员信息
					if(StringUtils.isNotBlank(medicalWorkerCode)) {
						practitionerVO = medicalRecordDataManageService.getCertificateByMedicalWorkCode(medicalWorkerCode);
					}
					// 手术操作术者
					if ("A5001".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("SZ" + opsIndex, medicalWorkerName);
						reflectHelper.setMethodValue("SZSFZH" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						reflectHelper.setMethodValue("SZBM" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());


						// 手术操作Ⅰ助
					} else if ("A5003".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("YZ" + opsIndex, medicalWorkerName);
						reflectHelper.setMethodValue("YZSFZH" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						reflectHelper.setMethodValue("YZBM" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
						// 手术操作Ⅱ助
					} else if ("A5004".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("EZ" + opsIndex, medicalWorkerName);
						reflectHelper.setMethodValue("EZSFZH" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						reflectHelper.setMethodValue("EZBM" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
						// 麻醉医师
					} else if ("A5002".equals(professionTitleCode)) {
						// 麻醉医师姓名
						reflectHelper.setMethodValue("MZYS" + opsIndex, medicalWorkerName);
						// 麻醉医师身份证号
						reflectHelper.setMethodValue("MZYSSFZH" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						// 麻醉医师执业证书编号
						reflectHelper.setMethodValue("MZYSBM" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
					} else if ("A5007".equals(professionTitleCode)) {
						// 麻醉医师2
						reflectHelper.setMethodValue("MZYSE" + opsIndex, medicalWorkerName);
						// 麻醉医师2身份证号
						reflectHelper.setMethodValue("MZYSSFZHE" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						// 麻醉医师2执业证书编号
						reflectHelper.setMethodValue("MZYSBME" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
					} else if ("A5008".equals(professionTitleCode)) {
						// 麻醉医师3
						reflectHelper.setMethodValue("MZYSSA" + opsIndex, medicalWorkerName);
						// 麻醉医师3身份证号
						reflectHelper.setMethodValue("MZYSSFZHSA" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						// 麻醉医师3执业证书编号
						reflectHelper.setMethodValue("MZYSBMSA" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
					} else if ("A5009".equals(professionTitleCode)) {
						// 麻醉医师4
						reflectHelper.setMethodValue("MZYSSI" + opsIndex, medicalWorkerName);
						// 麻醉医师5身份证号
						reflectHelper.setMethodValue("MZYSSFZHSI" + opsIndex, practitionerVO==null?null:practitionerVO.getIdCard());
						// 麻醉医师4执业证书编号
						reflectHelper.setMethodValue("MZYSBMSI" + opsIndex, practitionerVO==null?null:practitionerVO.getCertificateNo());
					}
				}

			}

			opsIndex++;
		}
	}

	/**
	 * 处理护理天数
	 *
	 * @param jsonMap
	 * @param homepageData
	 */
	private void handleNurseInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> nurseInfoMap = MapUtils.getMap(jsonMap, "nurseInfo");
		if (MapUtils.isNotEmpty(nurseInfoMap)) {
			// 特级护理天数
			homepageData.setTJHL_T(MapUtils.getString(nurseInfoMap, "specialNurseDayNumber"));
			// 一级护理天数
			homepageData.setYJHL_T(MapUtils.getString(nurseInfoMap, "firstLevelNurseDayNumber"));
			// 二级护理天数
			homepageData.setEJHL_T(MapUtils.getString(nurseInfoMap, "secondLevelNurseDayNumber"));
			// 三级护理天数
			homepageData.setSJHL_T(MapUtils.getString(nurseInfoMap, "threeLevelNurseDayNumber"));
		}
	}

	public List<String> getGuidList() {
		return guidList;
	}

	public void setGuidList(List<String> guidList) {
		this.guidList = guidList;
	}

	public MedicalRecordDataManageService getMedicalRecordDataManageService() {
		return medicalRecordDataManageService;
	}

	public void setMedicalRecordDataManageService(MedicalRecordDataManageService medicalRecordDataManageService) {
		this.medicalRecordDataManageService = medicalRecordDataManageService;
	}

	/**
	 * 设置病案初始化数据
	 */
	public void initHomepageData(ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		// 组织机构代码
		shandongHomepageExcelDTO.setZZJGDM(HomepageConstatnt.ORGANIZATION_ID);
		// 组织机构名称
		shandongHomepageExcelDTO.setJGMC(HomepageConstatnt.ORGANIZATION);
		// 对应的系统登录用户名
		shandongHomepageExcelDTO.setUSERNAME(HomepageConstatnt.USER_NAME);
	}

	/**
	 * 处理病案基本信息数据
	 *
	 * @param jsonMap
	 * @param shandongHomepageExcelDTO
	 */
	public void handleHomepageBaiscData(Map<String, Object> jsonMap,
			ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		// 基本信息
		Map<String, Object> basicInfoMap = MapUtils.getMap(jsonMap, "basicInfo");
		if (MapUtils.isEmpty(basicInfoMap)) {
			return;
		}
		// 医疗付款方式
		String medicalPayTypeCode = MapUtils.getString(basicInfoMap, "medicalPayTypeCode");
		if(StringUtils.isNotBlank(medicalPayTypeCode)) {
			shandongHomepageExcelDTO.setYLFKFS(convertMedicalPayType(medicalPayTypeCode));
		}

		// 健康卡号
		shandongHomepageExcelDTO.setJKKH(MapUtils.getString(basicInfoMap, "medicalHealthNumber"));
		// 住院次数
		shandongHomepageExcelDTO.setZYCS(MapUtils.getString(basicInfoMap, "visitNumber"));
		// 病案号
		shandongHomepageExcelDTO.setBAH(MapUtils.getString(basicInfoMap, "mrId"));
		// 姓名
		shandongHomepageExcelDTO.setXM(MapUtils.getString(basicInfoMap, "patientName"));
		// 性别
		shandongHomepageExcelDTO.setXB(MapUtils.getString(basicInfoMap, "sexCode"));
		// 出生日期
		String birthdayStr = MapUtils.getString(basicInfoMap, "birthday");
		if (StringUtils.isNotBlank(birthdayStr) && !birthdayStr.equals("null")) {
			shandongHomepageExcelDTO.setCSRQ(birthdayStr);
		}
		// 年龄
		String ageStr = MapUtils.getString(basicInfoMap, "yearOfAge");
		if(StringUtils.isEmpty(ageStr)) {
			shandongHomepageExcelDTO.setNL("0");
			// 入院时间-出院时间 计算天数
			try {
				// 出生日期
				Date birthday = DateUtil.dateParse("yyyy-MM-dd", birthdayStr);
				String inTimeStr = MapUtils.getString(basicInfoMap, "inHospitalDateTime");
				// 入院时间
				Date inTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", inTimeStr);
				int days = (int) ((inTime.getTime() - birthday.getTime()) / (1000*3600*24));
				shandongHomepageExcelDTO.setBZYZSNL(days + "");
			} catch (Exception e) {
				e.printStackTrace();
			}

		}else {
			shandongHomepageExcelDTO.setNL(ageStr);
		}


		// 国籍
		String nationalityName = MapUtils.getString(basicInfoMap, "nationalityName");
		if(StringUtils.isNotBlank(nationalityName)) {
			shandongHomepageExcelDTO.setGJ(medicalRecordDataManageService.getEnnameByName(nationalityName));
		}


		Map<String, Object> birthRegionalismMap = MapUtils.getMap(basicInfoMap, "birthRegionalism");
		if (MapUtils.isNotEmpty(birthRegionalismMap)) {
			// 出生地_省
			shandongHomepageExcelDTO.setCSD_SG(MapUtils.getString(birthRegionalismMap, "provinceCode"));
			// 出生地—市
			shandongHomepageExcelDTO.setCSD_SI(MapUtils.getString(birthRegionalismMap, "cityCode"));
			// 出生地—区县
			shandongHomepageExcelDTO.setCSD_QX(MapUtils.getString(birthRegionalismMap, "countyCode"));
			// 出生地—详细地址
			shandongHomepageExcelDTO.setCSD_DZ(MapUtils.getString(birthRegionalismMap, "fullAddress"));
		}

		// 籍贯—省
		Map<String, Object> nativePlaceRegionalismMap = MapUtils.getMap(basicInfoMap, "nativePlaceRegionalism");
		if (MapUtils.isNotEmpty(nativePlaceRegionalismMap)) {
			// 籍贯—省
			shandongHomepageExcelDTO.setJG_SG(MapUtils.getString(nativePlaceRegionalismMap, "provinceCode"));
			// 籍贯—市
			shandongHomepageExcelDTO.setJG_SI(MapUtils.getString(nativePlaceRegionalismMap, "cityCode"));

		}
		// 民族
		Integer nationCode = MapUtils.getInteger(basicInfoMap, "nationCode");
		if(nationCode!=null) {
			shandongHomepageExcelDTO.setMZ(nationCode==99?"66":nationCode+"");
		}

		// 身份证件类别
		shandongHomepageExcelDTO.setSFZJLB(MapUtils.getString(basicInfoMap, "documentTypeCode"));
		// 身份证号
		shandongHomepageExcelDTO.setSFZH(MapUtils.getString(basicInfoMap, "idNumber"));
		// 职业
		shandongHomepageExcelDTO.setZY(MapUtils.getString(basicInfoMap, "professionCode"));
		// 婚姻
		shandongHomepageExcelDTO.setHY(MapUtils.getString(basicInfoMap, "marriageCode"));

		// 现住址
		Map<String, Object> permanentAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"permanentAddressRegionalism");
		if (MapUtils.isNotEmpty(permanentAddressRegionalismMap)) {
			// 现住址—省
			shandongHomepageExcelDTO.setXZZ_SG(MapUtils.getString(permanentAddressRegionalismMap, "provinceCode"));
			// 现住址—市
			shandongHomepageExcelDTO.setXZZ_SI(MapUtils.getString(permanentAddressRegionalismMap, "cityCode"));
			// 现住址—区县
			shandongHomepageExcelDTO.setXZZ_QX(MapUtils.getString(permanentAddressRegionalismMap, "countyCode"));

			//
			shandongHomepageExcelDTO.setXZZ_DZ(MapUtils.getString(permanentAddressRegionalismMap, "fullAddress"));

		}
		// 电话
		shandongHomepageExcelDTO.setDH(MapUtils.getString(basicInfoMap, "permanentAddressPhone"));
		// 邮编
		shandongHomepageExcelDTO.setYB1(MapUtils.getString(basicInfoMap, "permanentAddressPostCode"));

		// 户口地址
		Map<String, Object> registeredAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"registeredAddressRegionalism");
		if (MapUtils.isNotEmpty(registeredAddressRegionalismMap)) {
			// 户口地址—省
			shandongHomepageExcelDTO.setHKDZ_SG(MapUtils.getString(registeredAddressRegionalismMap, "provinceCode"));
			// 户口地址—市
			shandongHomepageExcelDTO.setHKDZ_SI(MapUtils.getString(registeredAddressRegionalismMap, "cityCode"));
			// 户口地址—区县
			shandongHomepageExcelDTO.setHKDZ_QX(MapUtils.getString(registeredAddressRegionalismMap, "countyCode"));
			shandongHomepageExcelDTO.setHKDZ_DZ(MapUtils.getString(registeredAddressRegionalismMap, "fullAddress"));
		}

		// 户口邮编
		shandongHomepageExcelDTO.setYB2(MapUtils.getString(basicInfoMap, "registeredAddressPostCode"));

		// 工作单位名称
		shandongHomepageExcelDTO.setGZDWJDZMC(MapUtils.getString(basicInfoMap, "workUnitName"));

		// 工作单位
		Map<String, Object> workUnitRegionalismMap = MapUtils.getMap(basicInfoMap, "workUnitRegionalism");
		if (MapUtils.isNotEmpty(workUnitRegionalismMap)) {
			// 工作单位及地址—省
			shandongHomepageExcelDTO.setGZDWJDZ_SG(MapUtils.getString(workUnitRegionalismMap, "provinceCode"));

			// 工作单位及地址—市
			shandongHomepageExcelDTO.setGZDWJDZ_SI(MapUtils.getString(workUnitRegionalismMap, "cityCode"));

			// 工作单位及地址—区县
			shandongHomepageExcelDTO.setGZDWJDZ_QX(MapUtils.getString(workUnitRegionalismMap, "countyCode"));

			// 工作单位及地址—详细地址
			shandongHomepageExcelDTO.setGZDWJDZ_DZ(MapUtils.getString(workUnitRegionalismMap, "fullAddress"));

		}
		// 工作单位电话
		shandongHomepageExcelDTO.setDWDH(MapUtils.getString(basicInfoMap, "workUnitPhone"));
		// 工作单位邮政编码
		String workUnitPostCode = MapUtils.getString(basicInfoMap, "workUnitPostCode");
		shandongHomepageExcelDTO.setYB3(workUnitPostCode==null?"-":workUnitPostCode);
		// 联系人姓名
		shandongHomepageExcelDTO.setLXRXM(MapUtils.getString(basicInfoMap, "linkManName"));
		// 联系人关系
		String linkManRelativeRelationCode = MapUtils.getString(basicInfoMap, "linkManRelativeRelationCode");
		if(StringUtils.isNotBlank(linkManRelativeRelationCode)) {
			// 联系人关系8需要映射为9
			shandongHomepageExcelDTO.setGX("8".equals(linkManRelativeRelationCode)?"9":linkManRelativeRelationCode);
		}


		Map<String, Object> linkManAddressRegionalismMap = MapUtils.getMap(basicInfoMap, "linkManAddressRegionalism");
		if (MapUtils.isNotEmpty(linkManAddressRegionalismMap)) {
			// 联系人地址—省
			shandongHomepageExcelDTO.setDZ_SG(MapUtils.getString(linkManAddressRegionalismMap, "provinceCode"));

			// 联系人地址—市
			shandongHomepageExcelDTO.setDZ_SI(MapUtils.getString(linkManAddressRegionalismMap, "cityCode"));

			// 联系人地址—区县
			shandongHomepageExcelDTO.setDZ_QX(MapUtils.getString(linkManAddressRegionalismMap, "countyCode"));

			// 联系人地址—详细地址
			shandongHomepageExcelDTO.setDZ_DZ(MapUtils.getString(linkManAddressRegionalismMap, "fullAddress"));
		}

		// 联系人电话
		shandongHomepageExcelDTO.setDH2(MapUtils.getString(basicInfoMap, "linkManPhone"));

		// 入院途径
		String inHospitalTypeCode = MapUtils.getString(basicInfoMap, "inHospitalTypeCode");
		if(StringUtils.isNotBlank(inHospitalTypeCode)) {
			if("1".equals(inHospitalTypeCode)) {
				inHospitalTypeCode = "2";
			}else if("2".equals(inHospitalTypeCode)) {
				inHospitalTypeCode = "1";
			}
			shandongHomepageExcelDTO.setRYTJ(inHospitalTypeCode);
		}

		// 转诊医疗机构名称
		shandongHomepageExcelDTO.setZZYLJGMC(MapUtils.getString(basicInfoMap, "shiftToUnitName"));
		String inTime = MapUtils.getString(basicInfoMap, "inHospitalDateTime");

		if (StringUtils.isNotBlank(inTime) && !"null".equals(inTime)) {
			try {
				Date inHospitalTime = StringUtils.isNotEmpty(inTime)?DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", inTime):null;
				// 入院时间
				shandongHomepageExcelDTO.setRYSJ(inTime);
				// 入院时间 - 时
				shandongHomepageExcelDTO.setRYSJS(DateUtil.dateFormat("HH", inHospitalTime));
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 入院科室
		String inDeptCode = MapUtils.getString(basicInfoMap, "inDeptCode");
		if(StringUtils.isNotEmpty(inDeptCode)) {
			shandongHomepageExcelDTO.setRYKB(MapUtils.getString(getDeptMap(), inDeptCode));
		}


		// 入院病房
		shandongHomepageExcelDTO.setRYBF(MapUtils.getString(basicInfoMap, "inHospitalHouseName"));

		// 出院日期
		String outTimeStr = MapUtils.getString(basicInfoMap, "outHospitalDateTime");

		if (StringUtils.isNotBlank(outTimeStr) && !"null".equals(outTimeStr)) {

			try {
				// 出院日期
				Date outHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", outTimeStr);
				// 出院日期
				shandongHomepageExcelDTO.setCYSJ(outTimeStr);
				// 入院时间 - 时
				shandongHomepageExcelDTO.setCYSJS(DateUtil.dateFormat("HH", outHospitalTime));
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("出院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 出院科别
		String outDeptCode = MapUtils.getString(basicInfoMap, "outDeptCode");
		if(StringUtils.isNotEmpty(outDeptCode)) {
			shandongHomepageExcelDTO.setCYKB(MapUtils.getString(getDeptMap(), outDeptCode));
		}

		// 出院病房
		shandongHomepageExcelDTO.setCYBF(MapUtils.getString(basicInfoMap, "outHospitalHouseName"));


		// 实际住院天数
		shandongHomepageExcelDTO.setSJZYTS(MapUtils.getString(basicInfoMap, "inHospitalDayNumber"));

		// 入院诊断确诊时间
		String diagConfirmedDateTimeStr = MapUtils.getString(basicInfoMap, "diagConfirmedDateTime");
		if (StringUtils.isNotBlank(diagConfirmedDateTimeStr) && !"null".equals(diagConfirmedDateTimeStr)) {

			try {
				// 出院日期
				Date diagConfirmedDateTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", diagConfirmedDateTimeStr);
				// 出院日期
				shandongHomepageExcelDTO.setRYHQZRQ(DateUtil.dateFormat("yyyy-MM-dd", diagConfirmedDateTime));

			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院后确诊时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 有无药物过敏
		shandongHomepageExcelDTO.setYWGM(MapUtils.getString(basicInfoMap, "whetherDrugAllergyCode"));
		// 过敏药物
		shandongHomepageExcelDTO.setGMYW(MapUtils.getString(basicInfoMap, "drugAllergyDesc"));
		// 死亡患者尸检
		String SWHZSJ = MapUtils.getString(basicInfoMap, "autopsyCode");
		if (SWHZSJ != null && SWHZSJ.startsWith("-")) {
			SWHZSJ = null;
		}
		shandongHomepageExcelDTO.setSWHZSJ(SWHZSJ);

		// 离院方式
		shandongHomepageExcelDTO.setLYFS(MapUtils.getString(basicInfoMap, "outHospitalTypeCode"));
		// 医嘱转院，拟接收医疗机构名称
		shandongHomepageExcelDTO.setYZZY_YLJG(MapUtils.getString(basicInfoMap, "receiveUnitName"));
	}

	/**
	 * 处理诊断信息
	 *
	 * @param jsonMap      json数据
	 * @param homepageData 首页数据信息
	 */
	@SuppressWarnings("unchecked")
	private void handleDiagInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		// 从json中获取疾病信息
		Map<String, Object> diseaseDiagInfoMap = MapUtils.getMap(jsonMap, "hqmsDiseaseDiagInfo");
		if (MapUtils.isEmpty(diseaseDiagInfoMap)) {
			return;
		}
		// 获取门诊信息
		Map<String, Object> outpatientDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "outpatientDiagRecord");
		if (MapUtils.isNotEmpty(outpatientDiagRecordMap)) {
			String outpatientDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagName");
			String outpatientDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagCode");
			String diseaseDiagOriginalCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
			String diseaseDiagOriginalDesc = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
			// 门（急）诊诊断名称
			homepageData.setMZZD(StringUtils.isEmpty(outpatientDiagName)?diseaseDiagOriginalDesc:outpatientDiagName);
			// 门（急）诊诊断编码
			homepageData.setJBBM(StringUtils.isEmpty(outpatientDiagCode)?diseaseDiagOriginalCode:outpatientDiagCode);

			// 入院病情
			String rybq = MapUtils.getString(outpatientDiagRecordMap, "inHospitalDiseaseStateCode");

			// 入院病情
			homepageData.setRYSQK(null);

			// 入院诊断编码
			homepageData.setRYZDMC(StringUtils.isEmpty(outpatientDiagName)?diseaseDiagOriginalDesc:outpatientDiagName);

			// 入院诊断名称
			homepageData.setRYZDBM(StringUtils.isEmpty(outpatientDiagCode)?diseaseDiagOriginalCode:outpatientDiagCode);

		}

		// 主要诊断信息
		Map<String, Object> mainDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "mainDiagRecord");
		if (MapUtils.isNotEmpty(mainDiagRecordMap)) {
			String mainDiagName = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagName"));
			if(StringUtils.isEmpty(mainDiagName)) {
				mainDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
			}
			String mainDiagCode = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagCode"));
			if(StringUtils.isEmpty(mainDiagCode)) {
				mainDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
			}

			if (mainDiagCode != null && (mainDiagCode.endsWith("?") || mainDiagCode.endsWith("†"))) {
				mainDiagCode = mainDiagCode.replace("?", "+").replace("†", "+");
				List<Map<String, Object>> extraMainDiagMapList = (List<Map<String, Object>>) MapUtils
						.getObject(mainDiagRecordMap, "diseaseExtraDiagRecords");
				for (Map<String, Object> extraMainDiagMap : extraMainDiagMapList) {
					String diseaseExtraDiagCode = MapUtils.getString(extraMainDiagMap, "diseaseExtraDiagCode");
					if (StringUtils.isNotEmpty(diseaseExtraDiagCode) && diseaseExtraDiagCode.contains("*")) {
						mainDiagCode = mainDiagCode + diseaseExtraDiagCode;
					}
				}
			}

			// 出院主要诊断名称
			homepageData.setZYZD(mainDiagName);
			// 出院主要诊断编码
			homepageData.setJBDM(mainDiagCode);

			// 入院病情
			String rybq = MapUtils.getString(mainDiagRecordMap, "inHospitalDiseaseStateCode");
			// 出院主要诊断入院病情
			homepageData.setRYBQ(StringUtils.isEmpty(rybq) ? "4" : rybq);

			// 主要诊断出院情况
			homepageData.setCYQK(MapUtils.getString(mainDiagRecordMap, "treatResultCode"));
		}

		// 其他诊断
		List<Map<String, Object>> otherDiseaseDiagRecords = (List<Map<String, Object>>) MapUtils
				.getObject(diseaseDiagInfoMap, "diseaseDiagRecords");

		if (CollectionUtils.isNotEmpty(otherDiseaseDiagRecords)) {
			int otherDiagIndex = 1;
			for (Map<String, Object> otherDiseaseDiagRecord : otherDiseaseDiagRecords) {
				String otherDiagName = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagName");
				if (StringUtils.isEmpty(otherDiagName)) {
					otherDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
				}
				String otherDiagCode = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagCode");
				if (StringUtils.isEmpty(otherDiagCode)) {
					otherDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
				}
				if (StringUtils.isNotBlank(otherDiagCode)
						&& (otherDiagCode.endsWith("?") || otherDiagCode.endsWith("†"))) {
					otherDiagCode = otherDiagCode.replace("?", "+").replace("†", "+");
					List<Map<String, Object>> otherExtraDiagRecords = (List<Map<String, Object>>) MapUtils
							.getObject(otherDiseaseDiagRecord, "diseaseExtraDiagRecords");
					for (Map<String, Object> otherExtraDiagRecord : otherExtraDiagRecords) {
						String otherDiseaseExtraDiagCode = MapUtils.getString(otherExtraDiagRecord,
								"diseaseExtraDiagCode");

						if (StringUtils.isNotEmpty(otherDiseaseExtraDiagCode)
								&& otherDiseaseExtraDiagCode.contains("*")) {
							otherDiagCode = otherDiagCode + otherDiseaseExtraDiagCode;
						}
					}

				}

				ReflectHelper reflectHelper = new ReflectHelper(homepageData);// 创建工具类对象
				// 出院其他诊断名称
				reflectHelper.setMethodValue("QTZD" + otherDiagIndex, otherDiagName);
				// 出院其他诊断编码
				reflectHelper.setMethodValue("JBDM" + otherDiagIndex, otherDiagCode);
				// 出院其他诊断入院病情
				String rybq = MapUtils.getString(otherDiseaseDiagRecord, "inHospitalDiseaseStateCode");
				reflectHelper.setMethodValue("RYBQ" + otherDiagIndex, StringUtils.isEmpty(rybq) ? "4" : rybq);
				// 其他诊断出院情况
				reflectHelper.setMethodValue("CYQK" + otherDiagIndex,
						MapUtils.getString(otherDiseaseDiagRecord, "treatResultCode"));
				otherDiagIndex++;

			}
		}

		// 中毒的外部原因
		List<Map<String, Object>> damageAndVenenationDiagRecords = (List<Map<String, Object>>) MapUtils
							.getObject(diseaseDiagInfoMap, "damageAndVenenationDiagRecords");

		if (CollectionUtils.isNotEmpty(damageAndVenenationDiagRecords)) {
			Map<String, Object> damageAndVenenationDiagRecord = damageAndVenenationDiagRecords.get(0);
			String damageAndVenenationDiagName = MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagName");

			String damageAndVenenationDiagCode =  MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagCode");

			// 损伤、中毒外部原因名称
			homepageData.setWBYY(damageAndVenenationDiagName);
			// 损伤、中毒外部原因编码
			homepageData.setWBYYCODE(damageAndVenenationDiagCode);
		}

		// 病理诊断
		List<Map<String, Object>> pathologyDiagRecords = (List<Map<String, Object>>) MapUtils
							.getObject(diseaseDiagInfoMap, "pathologyDiagRecords");
		if (CollectionUtils.isNotEmpty(pathologyDiagRecords)) {
			Map<String, Object> pathologyDiagRecord = pathologyDiagRecords.get(0);
			String pathologyDiagName = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagName"));
			String pathologyDiagCode = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagCode"));
			// 病理诊断名称
			homepageData.setBLZD(pathologyDiagName);
			// 病理诊断编码
			homepageData.setJBMM(pathologyDiagCode);
			// 病理号
			homepageData.setBLH(MapUtils.getString(pathologyDiagRecord, "pathologyNumber"));

		}

	}

	/**
	 * 处理病案治疗信息数据
	 *
	 * @param jsonMap
	 * @param shandongHomepageExcelDTO
	 */
	public void handleCureInfoData(Map<String, Object> jsonMap, ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		Map<String, Object> cureInfoMap = MapUtils.getMap(jsonMap, "cureInfo");
		if (MapUtils.isEmpty(cureInfoMap)) {
			return;
		}

		// 新生儿出生体重（克）	XSECSTZ
		shandongHomepageExcelDTO.setXSECSTZ(MapUtils.getString(cureInfoMap, "babyBirthWeight"));
		// 新生儿出生体重（克）2	XSECSTZ1
		shandongHomepageExcelDTO.setXSECSTZ1(MapUtils.getString(cureInfoMap, "babyBirthWeight2"));
		// 新生儿出生体重（克）3	XSECSTZ2
		shandongHomepageExcelDTO.setXSECSTZ2(MapUtils.getString(cureInfoMap, "babyBirthWeight3"));
		// 新生儿出生体重（克）4	XSECSTZ3
		shandongHomepageExcelDTO.setXSECSTZ3(MapUtils.getString(cureInfoMap, "babyBirthWeight4"));
		// 新生儿出生体重（克）5	XSECSTZ4
		shandongHomepageExcelDTO.setXSECSTZ4(MapUtils.getString(cureInfoMap, "babyBirthWeight5"));
		// 新生儿入院体重（克）	XSERYTZ
		shandongHomepageExcelDTO.setXSERYTZ(MapUtils.getString(cureInfoMap, "babyInHospitalWeight"));

		// 最高诊断依据
		shandongHomepageExcelDTO.setZGZDYJ(MapUtils.getString(cureInfoMap, "malignantTumorHighestDiagBasisCode"));
		// ABO血型
		shandongHomepageExcelDTO.setXX(MapUtils.getString(cureInfoMap, "bloodTypeCode"));
		// RH血型
		shandongHomepageExcelDTO.setRH(MapUtils.getString(cureInfoMap, "rhBloodTypeCode"));
		// HBsAg
		shandongHomepageExcelDTO.setHBSAG(MapUtils.getString(cureInfoMap, "hbsAgeResultCode"));
		// HCV-Ab
		shandongHomepageExcelDTO.setHCVAb(MapUtils.getString(cureInfoMap, "hcvAbResultCode"));
		// HIV-Ab
		shandongHomepageExcelDTO.setHIVAb(MapUtils.getString(cureInfoMap, "hivAbResultCode"));
		// 日间手术
		String rjss = MapUtils.getString(cureInfoMap, "isDaySurgeryCode");
		if (StringUtils.isNotBlank(rjss)) {
			shandongHomepageExcelDTO.setSFWRJSS("2".equals(rjss) ? "0" : "1");
		}else {
			shandongHomepageExcelDTO.setSFWRJSS("0");
		}


		// 有创呼吸机使用时间
		Integer ventilatorServiceHour = 0;
		String invasiveVentilatorDay = MapUtils.getString(cureInfoMap, "invasiveVentilatorDay");
		if(StringUtils.isNotEmpty(invasiveVentilatorDay)) {
			try {
				ventilatorServiceHour+= (Integer.parseInt(invasiveVentilatorDay))*24;
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机天转小时出现错误,异常信息:{}",e.getMessage());
			}

		}
		String invasiveVentilatorHour = MapUtils.getString(cureInfoMap, "invasiveVentilatorHour");
		if(StringUtils.isNotEmpty(invasiveVentilatorHour)) {
			try {
				ventilatorServiceHour+= Integer.parseInt(invasiveVentilatorHour);
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机字符串小时转数字出现错误,异常信息:{}",e.getMessage());
			}

		}

		String invasiveVentilatorMinute = MapUtils.getString(cureInfoMap, "invasiveVentilatorMinute");
		if(StringUtils.isNotEmpty(invasiveVentilatorMinute)) {
			try {
				Integer minutes = Integer.parseInt(invasiveVentilatorMinute);
				ventilatorServiceHour+= minutes%60!=0?minutes/60+1:minutes/60;
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机字符串分钟转数字出现错误,异常信息:{}",e.getMessage());
			}

		}
		shandongHomepageExcelDTO.setYCHXJSYSJ(ventilatorServiceHour+"");


		// 重症监护室名称1 ZZJHSMC1
		shandongHomepageExcelDTO.setZZJHSMC1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1Code"));
		// 进入时间1 JRSJ1
		shandongHomepageExcelDTO.setJRSJ1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1StartTime"));
		// 退出时间1 TCSJ1
		shandongHomepageExcelDTO.setTCSJ1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1EndTime"));

		// 重症监护室名称2 ZZJHSMC2
		shandongHomepageExcelDTO.setZZJHSMC2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2Code"));
		// 进入时间2 JRSJ2
		shandongHomepageExcelDTO.setJRSJ2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2StartTime"));
		// 退出时间2 TCSJ2
		shandongHomepageExcelDTO.setTCSJ2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2EndTime"));

		// 重症监护室名称3 ZZJHSMC3
		shandongHomepageExcelDTO.setZZJHSMC3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3Code"));
		// 进入时间3 JRSJ3
		shandongHomepageExcelDTO.setJRSJ3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3StartTime"));
		// 退出时间3 TCSJ3
		shandongHomepageExcelDTO.setTCSJ3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3EndTime"));

		List<Map<String, Object>> medicalWorks = (List<Map<String, Object>>) MapUtils.getObject(cureInfoMap,
				"cureWorkers");

		if (CollectionUtils.isNotEmpty(medicalWorks)) {

			for (Map<String, Object> medicalWork : medicalWorks) {

				String professionTitleCode = MapUtils.getString(medicalWork, "professionTitleCode");
				String medicalWorkerName = MapUtils.getString(medicalWork, "medicalWorkerName");
				String medicalWorkerCode = MapUtils.getString(medicalWork, "medicalWorkerCode");
				PractitionerVO practitionerVO = null;
				// 执业人员信息
				if(StringUtils.isNotBlank(medicalWorkerCode)) {
					practitionerVO = medicalRecordDataManageService.getCertificateByMedicalWorkCode(medicalWorkerCode);
				}
				// 科主任
				if ("A1001".equals(professionTitleCode)) {
					// 科主任姓名
					shandongHomepageExcelDTO.setKZR(medicalWorkerName);
					// 科主任编码
					shandongHomepageExcelDTO.setKZRBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 科主任身份证号码
					shandongHomepageExcelDTO.setKZRSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 医疗组长
				} else if ("A1003".equals(professionTitleCode)) {
					// 医疗组长姓名
					shandongHomepageExcelDTO.setYLZZ(medicalWorkerName);
					// 医疗组长编码
					shandongHomepageExcelDTO.setYLZZBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 医疗组长身份证号码
					shandongHomepageExcelDTO.setYLZZSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 主任医师
				} else if ("A2001".equals(professionTitleCode)) {
					// 主任医师姓名
					shandongHomepageExcelDTO.setZRYS(medicalWorkerName);
					// 主（副主）任医师编码
					shandongHomepageExcelDTO.setZRYSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 主（副主）任医师身份证号码
					shandongHomepageExcelDTO.setZRYSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 主治医师
				} else if ("A2003".equals(professionTitleCode)) {
					// 主治医师姓名
					shandongHomepageExcelDTO.setZZYS(medicalWorkerName);
					// 主治医师编码
					shandongHomepageExcelDTO.setZZYSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 主治医师身份证号码
					shandongHomepageExcelDTO.setZZYSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 住院医师
				} else if ("A2005".equals(professionTitleCode)) {
					// 住院医师姓名
					shandongHomepageExcelDTO.setZYYS(medicalWorkerName);
					// 住院医师编码
					shandongHomepageExcelDTO.setZYYSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 住院医师身份证号码
					shandongHomepageExcelDTO.setZYYSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 责任护士
				} else if ("A3001".equals(professionTitleCode)) {
					// 责任护士姓名
					shandongHomepageExcelDTO.setZRHS(medicalWorkerName);
					// 责任护士编码
					shandongHomepageExcelDTO.setZRHSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 责任护士身份证号码
					shandongHomepageExcelDTO.setZRHSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 进修医师
				} else if ("A2006".equals(professionTitleCode)) {
					// 进修医师姓名
					shandongHomepageExcelDTO.setJXYS(medicalWorkerName);
					// 进修医师编码
					shandongHomepageExcelDTO.setJXYSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 进修医师身份证号码
					shandongHomepageExcelDTO.setJXYSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
				}
				// 实习医师
				else if ("A2008".equals(professionTitleCode)) {
					// 实习医师姓名
					shandongHomepageExcelDTO.setSXYS(medicalWorkerName);
					// 编码员
				} else if ("A4001".equals(professionTitleCode)) {
					// 编码员姓名
					shandongHomepageExcelDTO.setBMY(medicalWorkerName);
					// 编码员身份证号码
					shandongHomepageExcelDTO.setBMYSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 质控医师
				} else if ("A2009".equals(professionTitleCode)) {
					// 质控医师姓名
					shandongHomepageExcelDTO.setZKYS(medicalWorkerName);
					// 质控医师编码
					shandongHomepageExcelDTO.setZKYSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 质控医师身份证号码
					shandongHomepageExcelDTO.setZKYSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
					// 质控护士
				} else if ("A3003".equals(professionTitleCode)) {
					// 质控护士姓名
					if(StringUtils.isNotBlank(medicalWorkerName)) {
						shandongHomepageExcelDTO.setZKHS(medicalWorkerName.equals("001682")?"武美玲":medicalWorkerName);

					}
					//shandongHomepageExcelDTO.setZKHS(medicalWorkerName.equals("001682")?"武美玲":medicalWorkerName);
					// 质控护士编码
					shandongHomepageExcelDTO.setZKHSBM(practitionerVO==null?null:practitionerVO.getCertificateNo());
					// 质控护士身份证号码
					shandongHomepageExcelDTO.setZKHSSFZH(practitionerVO==null?null:practitionerVO.getIdCard());
				}
			}

			// 病案质量
			shandongHomepageExcelDTO.setBAZL(MapUtils.getString(cureInfoMap, "medicalRecordQualityCode"));
			// 质控日期
			String qualityTimeStr = MapUtils.getString(cureInfoMap, "qualityControlDateTime");
			if (StringUtils.isNotBlank(qualityTimeStr)) {
				try {
					Date qualityDateTime = StringUtils.isNotEmpty(qualityTimeStr)?DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", qualityTimeStr):null;
					shandongHomepageExcelDTO.setZKRQ(DateUtil.dateFormat("yyyy-MM-dd", qualityDateTime));
				} catch (Exception e) {
					e.printStackTrace();
					logger.error("质控日期转换失败,异常信息:" + e.getMessage());
				}
			}

		}

		// 入径情况
		shandongHomepageExcelDTO.setRJQK(MapUtils.getString(cureInfoMap, "whetherEnterClinicalPathsCode"));
		// 完成情况
		shandongHomepageExcelDTO.setWCQK(MapUtils.getString(cureInfoMap, "whetherFinishClinicalPathsCode"));
		// 变异情况
		shandongHomepageExcelDTO.setBYQK(MapUtils.getString(cureInfoMap, "whetherConditionVariationCode"));
		// 是否有出院31日内再住院计划
		shandongHomepageExcelDTO.setSFZZYJH(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Code"));
		// 出院31天再住院计划目的
		shandongHomepageExcelDTO.setMD(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Description"));

		// 颅脑损伤患者入院前昏迷时间（天）
		String dayOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "dayOfBeforeInHospitalComa");
		shandongHomepageExcelDTO.setRYQ_T(StringUtils.isEmpty(dayOfBeforeInHospitalComa)?"0":dayOfBeforeInHospitalComa);
		// 颅脑损伤患者入院前昏迷时间（小时）
		String hourOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "hourOfBeforeInHospitalComa");
		shandongHomepageExcelDTO.setRYQ_XS(StringUtils.isEmpty(hourOfBeforeInHospitalComa)?"0":hourOfBeforeInHospitalComa);
		// 颅脑损伤患者入院前昏迷时间（分钟）
		String minuteOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "minuteOfBeforeInHospitalComa");
		shandongHomepageExcelDTO.setRYQ_F(StringUtils.isEmpty(minuteOfBeforeInHospitalComa)?"0":minuteOfBeforeInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（天）
		String dayOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "dayOfAfterInHospitalComa");
		shandongHomepageExcelDTO.setRYH_T(StringUtils.isEmpty(dayOfAfterInHospitalComa)?"0":dayOfAfterInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（小时）
		String hourOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "hourOfAfterInHospitalComa");
		shandongHomepageExcelDTO.setRYH_XS(StringUtils.isEmpty(hourOfAfterInHospitalComa)?"0":hourOfAfterInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（分钟）
		String minuteOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "minuteOfAfterInHospitalComa");
		shandongHomepageExcelDTO.setRYH_F(StringUtils.isEmpty(minuteOfAfterInHospitalComa)?"0":minuteOfAfterInHospitalComa);
	}

	public Map<String, Object> getAnaesthesiaMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		// 01 全身麻醉
		map.put("1", "01");
		// 0101 吸入麻醉 （气管内插管、喉罩、面罩）
		map.put("11", "0101");
		// 0102 静脉麻醉 （全凭静脉麻醉）
		map.put("12", "0102");
		// 0103 静吸复合麻醉
		map.put("41", "0103");
		// 0104 基础麻醉 （直肠注入、肌肉注射）
		map.put("13", "0104");
		// 02 区域麻醉
		// map.put("2", "02");
		// 0201 椎管内麻醉
		map.put("2", "0201");
		// 020101 蛛网膜下腔阻滞 ||蛛网膜下腔阻滞麻醉
		map.put("21", "020101");
		// 020102 硬膜外间隙阻滞（含骶管阻滞）||硬脊膜外腔阻滞麻醉
		map.put("22", "020102");
		// 3 局部麻醉
		map.put("3", "03");
		// 31 神经丛阻滞麻醉
		map.put("31", "0202");
		// 32神经节阻滞麻醉
		map.put("32", "0202");
		// 33神经阻滞麻醉
		map.put("33", "0202");
		// 34 区域阻滞麻醉
		map.put("34", "99");
		// 35局部浸润麻醉
		map.put("35", "0302");
		// 36表面麻醉
		map.put("36", "0301");
		// 4 复合麻醉
		map.put("4", "05");
		// 41 静吸复合麻醉
		// map.put("41", "0502");
		// 42 针药复合麻醉
		map.put("42", "0502");
		// 43 神经丛与硬膜外阻滞复合麻醉
		map.put("43", "99");
		// 44 全麻复合全身降温
		map.put("44", "0503");
		// 45 全麻复合控制性降压
		map.put("45", "0503");
		// 9 其他麻醉方法
		map.put("9", "99");
		// 9 其他麻醉方法

		return map;
	}


	private static Map<String,Object> getDeptMap(){
		Map<String,Object> map = new HashMap<String, Object>();
		//map.put("2001", "03.05");
		map.put("2001", "19.10");
		map.put("2002", "03.05");
		map.put("2003", "03.04");

		map.put("2004", "03.04");
		map.put("2005", "03.06");
		map.put("2006", "03.07");
		map.put("2007", "03.03");
		map.put("2008", "03.03");
		map.put("20106", "03.03");


		map.put("2009", "16");
		map.put("2010", "03.02");
		map.put("2011", "03.01");
		map.put("2038", "03.01");
		map.put("2012", "04.01");
		map.put("2013", "04.01");
		map.put("2014", "08");
		//map.put("2015", "04.01");
		map.put("2015", "04.01.13");
		// 骨科一区病区
		map.put("2016", "04.03");
		// 骨科二区病区
		map.put("2017", "04.03");
		// 骨科一病区单元
		map.put("20045", "04.03");
		// 骨科一病区
		map.put("20059", "04.03");
		map.put("2018", "04.05");
		map.put("2019", "04.04");
		map.put("2020", "04.02");

		map.put("2021", "05.01");
		map.put("2022", "05.02");
		map.put("2023", "05.02");
		map.put("2024", "05.02");
		map.put("2025", "07");
		map.put("2026", "07");
		map.put("2027", "07.01");
		map.put("2028", "10");
		map.put("2029", "12");
		map.put("2030", "11");
		map.put("2031", "21");
		map.put("2032", "28");
		map.put("20001", "03.05");
		map.put("20201", "03.05");
		map.put("20002", "03.04");
		map.put("20003", "03.04");

		map.put("20004", "03.06");
		map.put("20005", "03.07");
		map.put("20006", "03.03");
		map.put("20007", "03.03");
		map.put("20106", "03.03");

		map.put("20008", "16");
		map.put("20009", "03.02");
		map.put("20010", "03.01");
		map.put("20110", "03.01");

		map.put("20011", "04.01");

		map.put("20012", "04.01");
		map.put("20018", "08");
		map.put("20013", "04.01");
		map.put("20059", "04.03");
		map.put("20014", "04.03");
		map.put("20015", "04.05");

		map.put("20016", "04.04");
		map.put("20017", "04.02");
		map.put("20019", "05.01");
		map.put("20058", "05.02");
		map.put("20057", "05.02");
		map.put("20071", "05.02");


		map.put("20023", "07");
		map.put("20024", "07");
		map.put("20025", "07");
		map.put("20026", "10");
		map.put("20028", "12");
		map.put("20027", "11");

		map.put("20072", "21");
		map.put("20029", "28");
		map.put("30011", "21");
		map.put("20058", "05.02");
		// 骨科二病区
		map.put("20014", "04.03");

		map.put("20057", "05.02");
		// 骨科二病区单元
		map.put("20145", "04.03");

		// 手足外科
		map.put("2043", "04.03.13");
		// 烧伤整形外科病区
		map.put("2043", "04.07");
		// 感染性疾病科扩展病区
		map.put("2044", "16");
		// 烧伤整形病区
		map.put("2045", "04.07");
		// 急诊医学科病区
		map.put("2041", "20");
		// 儿科扩展病区
		map.put("2056", "07");

		//2063  中医日间病房一病区
		map.put("2063", "50");
		// 中医日间病房二病区
		map.put("2067", "50");
		// 安宁疗护一病区
		map.put("2064", "24");
		// 安宁疗护二病区
		map.put("2065", "24");
		// 安宁疗护三病区
		map.put("2066", "24");
		// 肿瘤日间病房一病区
		map.put("2068", "19");
		// 肿瘤日间病房二病区
		map.put("2069", "19");
		// 重症医学科扩展病房
		map.put("2048", "28");

		return map;

	}

	/**
	 * 医疗付费方式字典和卫统报表字典转换
	 */
	private String convertMedicalPayType(String  medicalPayTypeCode) {
		String switchCode = null;
		if("01".equals(medicalPayTypeCode)) {
			switchCode ="1.1";
		}else if("02".equals(medicalPayTypeCode)) {
			switchCode ="2.1";
		}else if("03".equals(medicalPayTypeCode)) {
			switchCode ="3.1";
		}else if("04".equals(medicalPayTypeCode)) {
			switchCode ="4";
		}else if("05".equals(medicalPayTypeCode)) {
			switchCode ="5";
		}else if("06".equals(medicalPayTypeCode)) {
			switchCode ="6";
		}else if("07".equals(medicalPayTypeCode)) {
			switchCode ="7";
		}else if("08".equals(medicalPayTypeCode)) {
			switchCode ="8";
		}else if("99".equals(medicalPayTypeCode)) {
			switchCode ="9";
		}
		return switchCode;
	}

	/**
	 * 切口等级转换
	 * @param incisionType
	 * @return
	 */
	private String convertIncisionType(String incisionType) {
		String switchCode = null;
		if("0".equals(incisionType)) {
			switchCode ="1";
		}else if("1".equals(incisionType)) {
			switchCode ="2";
		}else if("2".equals(incisionType)) {
			switchCode ="3";
		}else if("3".equals(incisionType)) {
			switchCode ="4";
		}else if("9".equals(incisionType)) {
			switchCode ="1";
		}
		return switchCode;
	}


}
